package com.sk.commonadapter_android.adapter;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import java.util.List;

/**
 * @Author yemao
 * @Email yrmao9893@163.com
 * @Date 2017/6/13
 * @Des 多布局RecyclerViewAdapter!
 */

public abstract class CommonMultiTypeRecyclerViewAdapter<DATA> extends CommonRecyclerViewAdapter<DATA> {
    private MultiTypeSupport<DATA> mMultiTypeSupport;

    public CommonMultiTypeRecyclerViewAdapter(Context mContext, @LayoutRes int mLayoutId, MultiTypeSupport<DATA> mMultiTypeSupport) {
        super(mContext, mLayoutId);
        this.mMultiTypeSupport = mMultiTypeSupport;
    }

    public CommonMultiTypeRecyclerViewAdapter(Context mContext, @LayoutRes int mLayoutId, List<DATA> mData, MultiTypeSupport<DATA> mMultiTypeSupport) {
        super(mContext, mLayoutId, mData);
        this.mMultiTypeSupport = mMultiTypeSupport;
    }

    @Override
    public CommonViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mMultiTypeSupport != null) {
            mLayoutId=viewType;
            return new CommonViewHolder(LayoutInflater.from(mContext).inflate(mLayoutId,parent,false));
        }
        return super.onCreateViewHolder(parent, viewType);
    }

    @Override
    public int getItemViewType(int position) {
        if (mMultiTypeSupport!=null)
            return mMultiTypeSupport.getLayoutId(mData.get(position));
        return super.getItemViewType(position);
    }

}
